home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
090
/
byt0187b.arc
/
LISTINGS.DOC
< prev
next >
Wrap
Text File
|
1986-10-28
|
6KB
|
267 lines
program filewrite;
{ UCSD Pascal program to write a 64K data file }
{ in 512 chunks of 128 bytes each }
const
CHUNK_SIZE = 128; { size of chunks in bytes }
N_CHUNKS = 512; { number of chunks to write }
type
chunk_array = packed array [1..CHUNK_SIZE] of char;
chunk_file = file of chunk_array;
var
chunk : chunk_array; { one chunk }
cf : chunk_file; { file variable for data file }
i : integer; { loop control variable }
begin { filewrite }
for i := 1 to CHUNK_SIZE do
chunk[i] := chr(ord('1') + (i - 1) mod 8);
rewrite(cf, 'TEST');
for i := 1 to N_CHUNKS do begin
cf^ := chunk;
put(cf)
end;
close(cf, LOCK)
end.
Listing 1
UCSD Pascal 64Kbyte File╨writing Benchmark
program fileread;
{ UCSD Pascal program to read a 64K data file }
{ in 512 chunks of 128 bytes each }
const
CHUNK_SIZE = 128; { size of chunks in bytes }
N_CHUNKS = 512; { number of chunks to read }
type
chunk_array = packed array [1..CHUNK_SIZE] of char;
chunk_file = file of chunk_array;
var
chunk : chunk_array; { one chunk }
cf : chunk_file; { file variable for data file }
i : integer; { loop control variable }
begin { fileread }
reset(cf, 'TEST');
chunk := cf^;
for i := 2 to N_CHUNKS do begin
get(cf);
chunk := cf^;
end;
close(cf)
end.
Listing 2
UCSD Pascal 64Kbyte File╨reading Benchmark
program calculations;
{ UCSD Pascal program to perform series of real }
{ multiplications and divisions }
const
MAX = 5000; { number of repetitions }
var
a, b, c : real; { used in calculations }
i : integer; { loop control variable }
begin { calculations }
a := 2.71828;
b := 3.14159;
c := 1.0;
for i := 1 to MAX do begin
c := c * a;
c := c * b;
c := c / a;
c := c / b
end;
writeln('Error : ', c - 1.0)
end.
Listing 3
UCSD Pascal Calculation Benchmark
program sieve;
{ UCSD Pascal Sieve of Eratosthenes Benchmark }
const
SIZE = 7000; { size of array for standard benchmark }
var
flags : array [0..SIZE] of Boolean;
i, prime, k, count, iter: integer;
begin { sieve }
writeln('10 iterations');
for iter := 1 to 10 do begin
count := 0;
for i := 0 to SIZE do
flags[i] := TRUE;
for i := 0 to SIZE do
if flags[i] then begin
prime := i + i + 3;
k := i + prime;
while k <= SIZE do begin
flags[k] := FALSE;
k := k + prime
end;
count := count + 1
end
end;
writeln(count, ' primes')
end.
Listing 4
UCSD Pascal Sieve of Eratosthenes Benchmark
MODULE filewrite;
FROM Files IMPORT
FILE, FileState, Create, Close, WriteBytes;
FROM SYSTEM IMPORT
ADR;
CONST
CHUNKSIZE = 128; (* size of chunks in bytes *)
NCHUNKS = 512; (* number of chunks to write *)
TYPE
chunkarray = ARRAY [1..CHUNKSIZE] OF CHAR;
VAR
chunk : chunkarray; (* one chunk *)
cf : FILE; (* chunk file variable *)
i : CARDINAL; (* loop control variable *)
junk : CARDINAL; (* status from WriteBytes *)
fs : FileState; (* status from Create/Close *)
name : ARRAY [0..30] OF CHAR; (* file name *)
BEGIN
FOR i := 1 TO CHUNKSIZE DO
chunk[i] := CHR(ORD('1') + (i - 1) MOD 8)
END;
name := "TEST.DATA";
fs := Create(cf, name);
FOR i := 1 TO NCHUNKS DO
junk := WriteBytes(cf, ADR(chunk), CHUNKSIZE)
END;
fs := Close(cf)
END filewrite.
Listing 5
Modula╨2 64Kbyte File Writing Benchmark
MODULE fileread;
FROM Files IMPORT
FILE, FileState, Open, Close, ReadBytes;
FROM SYSTEM IMPORT
ADR;
CONST
CHUNKSIZE = 128; (* size of chunks in bytes *)
NCHUNKS = 512; (* number of chunks to write *)
TYPE
chunkarray = ARRAY [1..CHUNKSIZE] OF CHAR;
VAR
chunk : chunkarray; (* one chunk *)
cf : FILE; (* chunk file variable *)
i : CARDINAL; (* loop control variable *)
junk : CARDINAL; (* status from ReadBytes *)
fs : FileState; (* status from Open & Close *)
name : ARRAY [0..30] OF CHAR; (* file name *)
BEGIN
name := "TEST.DATA";
fs := Open(cf, name);
FOR i := 1 TO NCHUNKS DO
junk := ReadBytes(cf, ADR(chunk), CHUNKSIZE)
END;
fs := Close(cf);
END fileread.
Listing 6
Modula╨2 64Kbyte File Reading Benchmark
MODULE calculations;
(* Modula╨2 program to perform a series of real *)
(* multiplications and divisions *)
FROM RealInOut IMPORT
WriteReal;
FROM InOut IMPORT
WriteString, WriteLn;
CONST
MAX = 5000; (* number of iterations *)
VAR
a, b, c : REAL; (* used in calculations *)
i : CARDINAL; (* loop control variable *)
BEGIN
a := 2.71828;
b := 3.14159;
c := 1.0;
FOR i := 1 TO MAX DO
c := c * a;
c := c * b;
c := c / a;
c := c / b
END;
WriteString('Error = ');
WriteReal(c - 1.0, 10);
WriteLn
END calculations.
Listing 7
Modula╨2 Real Calculations Benchmark
MODULE sieve;
FROM InOut IMPORT
WriteLn, WriteString, WriteCard;
CONST
SIZE = 7000;
VAR
flags : ARRAY [0..SIZE] OF BOOLEAN;
i, prime, k, count, iter : CARDINAL;
BEGIN
WriteString('10 iterations');
FOR iter := 1 TO 10 DO
count := 0;
FOR i := 0 TO SIZE DO
flags[i] := TRUE
END;
FOR i := 0 TO SIZE DO
IF flags[i] THEN
prime := i + i + 3;
k := i + prime;
WHILE k <= SIZE DO
flags[k] := FALSE;
k := k + prime
END;
INC(count)
END
END
END;
WriteCard(count, 1);
WriteString(' primes');
WriteLn
END sieve.
Listing 8
Modula╨2 Sieve of Eratosthenes Benchmark
Program Benchmarks